#include "waveformgenerator.h"
const double WaveformGenerator::PI = 3.141592654;
WaveformGenerator::WaveformGenerator() {
}

WaveformGenerator::WaveformGenerator(double frequency, double sampleRate) {
	this->frequency = frequency;
	this->sampleRate = sampleRate;
}
double *WaveformGenerator::generate(unsigned long length) {
	double  points[length];

	for (unsigned long i = 0; i < length; i++) {
		double v = 128 + 127 * sin(2 * PI * i / this->sampleRate * this->frequency);
		points.append(v);
	}

	return points;
}

double *WaveformGenerator::generateByMillisecond(double time) {
	double length = time * this->sampleRate / 1000;
	return generate(length);
}

double *WaveformGenerator::generateByCycle(double cycle) {
	double x =  cycle / this->frequency * this->sampleRate ;
	return generate(x);
}
